<template>
  <div class="searchInfo_container" v-loading="domLoading2">
    <div class="searchInfo_container_title">
      <div v-if="type == 1">找到{{ info.songCount }}首单曲</div>
      <div v-else-if="type == 100">找到{{ info.artistCount }}位歌手</div>
      <div v-else-if="type == 1014">找到{{ info.videoCount }}个视频</div>
      <div v-else-if="type == 1000">找到{{ info.playlistCount }}个歌单</div>
      <div v-else>找到{{ info.userprofileCount }}位用户</div>
    </div>
    <div class="searchInfo_container_nav">
      <div
        class="searchInfo_container_nav_inside"
        :class="{ searchInfo_container_nav_inside_active: item.id == type }"
        @click="changeNav(item.id)"
        v-for="item in nav"
        :key="item.id"
      >
        {{ item.name }}
      </div>
    </div>

    <div v-loading="domLoading">
      <div class="singList" v-if="type == 1">
        <div class="singList_title" style="margin-bottom: 15px">
          <div class="singList_title_write"></div>
          <div class="singList_title_caozuo">操作</div>
          <div class="singList_title_biaoti">标题</div>
          <div class="singList_title_geshou">歌手</div>
          <div class="singList_title_zhuanji">专辑</div>
          <div class="singList_title_shijian">时间</div>
        </div>
        <div
          class="singList_title"
          v-for="(item, index) in info.songs"
          :key="item.id"
        >
          <div class="singList_title_write">
            {{(index + 1) &lt; 10 ? "0" + (index + 1) : index + 1  }}
          </div>
          <div class="singList_title_caozuo">
            <i
              @click="downMP3(item.id, item.name)"
              style="font-size: 16px"
              class="el-icon-download"
            />
          </div>
          <div
            @click="boFangSing(item.name, item.ar, item.al.picUrl, item.id)"
            v-html="changeColor(item.name)"
            class="singList_title_biaoti"
            style="
                color: black;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              "
          >
            {{ item.name }}
          </div>
          <div
            class="singList_title_geshou"
            style="
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              "
          >
            <span
              v-html="changeColor(childItem.name)"
              v-for="(childItem, index) in item.ar"
              :key="childItem.id"
            >
              {{
                (index == item.ar.length - 1 && childItem.name) ||
                  childItem.name + "/"
              }}
            </span>
          </div>

          <div
            v-html="changeColor(item.al.name)"
            class="singList_title_zhuanji"
            style="
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              "
          >
            {{ item.al.name }}
          </div>
          <div class="singList_title_shijian">01:38</div>
        </div>
      </div>
      <div class="geShouList" v-else-if="type == 100">
        <div
          class="geShouList_inside"
          v-for="item in info.artists"
          :key="item.id"
          @click="jumpGeShou(item.id)"
        >
          <el-image lazy :src="item.img1v1Url" />
          <div
            class="geShouList_inside_name"
            v-html="changeColor(item.name)"
          ></div>
          <div v-if="item.transNames" class="geShouList_inside_transNames">
            (<span
              v-html="changeColor(childItem)"
              v-for="(childItem, index) in item.transNames"
              :key="index"
            >
              {{
                (index == item.transNames.length - 1 && childItem) ||
                  childItem + "/"
              }} </span
            >)
          </div>
        </div>
      </div>
      <div class="shiping_container_contact" v-else-if="type == 1014">
        <div
          class="shiping_container_contact_inside"
          v-for="(item, index) in info.videos"
          :key="index"
          @click="goShiPing(item.vid)"
        >
          <div class="shiping_container_contact_inside_img">
            <el-image lazy :src="item.coverUrl"></el-image>
            <span class="shiping_container_contact_inside_durationms">{{
              times(item.durationms)
            }}</span>
          </div>
          <div
            v-html="changeColor(item.title)"
            class="shiping_container_contact_inside_title"
          ></div>
          <div class="shiping_container_contact_inside_arc">
            <span
              v-for="(childItem, index) in item.creator"
              :key="childItem.userId"
            >
              {{
                (index == item.creator.length - 1 && childItem.userName) ||
                  childItem.userName + "/"
              }}
            </span>
          </div>
        </div>
      </div>
      <div class="sousuo_gedan" v-else-if="type == 1000">
        <div
          class="sousuo_gedan_inside"
          v-for="item in info.playlists"
          :key="item.id"
          @click="jumpGeDan(item.id)"
        >
          <div class="sousuo_gedan_inside_left">
            <el-image :src="item.coverImgUrl" lazy />
            <div
              v-html="changeColor(item.name)"
              class="sousuo_gedan_inside_left_name"
            ></div>
          </div>
          <div class="sousuo_gedan_inside_middle">{{ item.trackCount }}首</div>
          <div class="sousuo_gedan_inside_right">
            <span class="sousuo_gedan_inside_right_by">by</span>
            <div
              @click.stop="jumpYongHu(item.userId)"
              class="sousuo_gedan_inside_right_name"
              v-html="changeColor(item.creator.nickname)"
            ></div>
          </div>
        </div>
      </div>
      <div class="yonghu_contact" v-else>
        <div
          class="yonghu_contact_inside"
          v-for="item in info.userprofiles"
          :key="item.userId"
          @click="jumpYongHu(item.userId)"
        >
          <div class="yonghu_contact_inside_left">
            <el-image :src="item.avatarUrl" lazy />
          </div>
          <div class="yonghu_contact_inside_middle">
            <div
              style="margin-right:5px;"
              v-html="changeColor(item.nickname)"
            ></div>

            <el-image lazy :src="item.gender == 2 ? sexImg : sexImg2" />
          </div>
          <div class="yonghu_contact_inside_right">
            <div v-if="item.signature">
              {{ item.signature }}
            </div>
            <div v-else>无</div>
          </div>
        </div>
      </div>
    </div>

    <el-dialog
      title="下载音质选择"
      :visible.sync="centerDialogVisible"
      width="30%"
      center
    >
      <el-radio-group v-model="fileId" v-if="isSingDown">
        <div v-for="(item, index) in toneQuality" :key="index" class="dialog">
          <el-radio :label="item.id">{{ item.name }}</el-radio>
        </div>
      </el-radio-group>
      <div class="noSing" v-else>该歌曲不可下载</div>
      <div class="buttons">
        <div
          class="buttons_inside"
          :style="{
            justifyContent: isSingDown == true ? 'space-between' : 'center',
          }"
        >
          <el-button v-show="isSingDown" round class="quereng" @click="dowmFile"
            >确认</el-button
          >
          <el-button round class="quxiao" @click="centerDialogVisible = false"
            >取消</el-button
          >
        </div>
      </div>
    </el-dialog>
    <div class="pagination">
      <el-pagination
        @current-change="changePage"
        background
        layout="prev, pager, next"
        :total="100"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { boFangSing,downFile } from "../../../common/mixin/commonJs";
import { Cloudsearch } from "../../../api/index";
export default {
  mixins: [boFangSing,downFile],
  created() {
    this.domLoading2 = true;
    this.init(this.type);
  },
  methods: {
    goShiPing(id){
      const status = 2
      this.$router.push({
        path: "/video",
        query: {
          id,
          status
        },
      });
    },
    init(type, total) {
      Cloudsearch({
        keywords: this.$route.query.searchValue,
        type,
        offset: total ? total * 30 : 0,
      }).then((res) => {
        console.log(res.result);
        this.info = res.result;
        this.domLoading2 = false;
        this.domLoading = false;
      });
    },
    times(time) {
      const hour =
        parseInt(time / 3600) < 10
          ? "0" + parseInt(time / 3600)
          : parseInt(time / 3600);
      const min =
        parseInt((time % 3600) / 60) < 10
          ? "0" + parseInt((time % 3600) / 60)
          : parseInt((time % 3600) / 60);
      const sec =
        parseInt((time % 3600) % 60) < 10
          ? "0" + parseInt((time % 3600) % 60)
          : parseInt((time % 3600) % 60);
      return hour + ":" + min + ":" + sec;
    },
    changeColor(str) {
      const reg = new RegExp(this.$route.query.searchValue, "g");
      return str.replace(
        reg,
        `<span style="color: rgb(118, 123, 196);">${this.$route.query.searchValue}</span>`
      );
    },
    jumpGeDan(id) {
      this.$router.push({
        path: "/geDanInfo",
        query: {
          id
        },
      });
    },
    jumpGeShou(id) {
      this.$router.push({
        path: "/geShou",
        query: {
          id,
        },
      });
    },
    jumpYongHu(id) {
      this.$router.push({
        path: "/yongHu",
        query: {
          id,
        },
      });
    },
    changePage(e) {
      this.domLoading = true;
      this.init(this.type, e);
    },
    changeNav(id) {
      this.domLoading2 = true;
      this.type = id;
      this.init(this.type);
    }
  },
  data() {
    return {
      sexImg: require("../../../assets/nv.png"),
      sexImg2: require("../../../assets/nan.png"),
      isSingDown: true,
      singInfo: {
        id: null,
        name: "",
      },
      info: {},
      fileId: 3,
      type: 1,
      centerDialogVisible: false,
      domLoading2: false,
      domLoading: false,
      toneQuality: [
        {
          id: 1,
          name: "标准 (128kbit/s)",
        },
        {
          id: 2,
          name: "较高 (192kbit/s)",
        },
        {
          id: 3,
          name: "极高 (320kbit/s)",
        },
      ],
      nav: [
        {
          name: "单曲",
          id: 1,
        },
        {
          name: "歌手",
          id: 100,
        },
        {
          name: "视频",
          id: 1014,
        },
        {
          name: "歌单",
          id: 1000,
        },
        {
          name: "用户",
          id: 1002,
        },
      ],
    };
  },
};
</script>

<style lang="scss" scoped>
@import "../../../common/css/commonStyle";
.el-radio__input.is-checked .el-radio__inner {
  background: $wangYiYunColor;
  border-color: $wangYiYunColor;
}
.searchInfo_container {
  width: 95%;
  padding-top: 20px;
  .searchInfo_container_title {
    font-size: 18px;
    font-weight: 900;
    margin-bottom: 20px;
  }
  .searchInfo_container_nav {
    display: flex;
    justify-content: space-between;
    width: 300px;
    .searchInfo_container_nav_inside {
      width: 20%;
      @include flex;
      cursor: pointer;
      padding-top: 10px;
      padding-bottom: 10px;
    }
    .searchInfo_container_nav_inside_active {
      border-bottom: 2px solid $wangYiYunColor;
      font-size: 20px;
      font-weight: 900;
    }
  }
  .singList {
    width: 93%;
    margin: auto;
    padding-top: 30px;
    padding-bottom: 30px;
    .singList_title {
      display: flex;
      height: 30px;
      font-size: 14px;
      color: gray;
      .singList_title_write {
        width: 8%;
        height: 100%;
        //background: #66b1ff;
      }
      .singList_title_caozuo {
        width: 10%;
        height: 100%;
        //background: red;
        .el-icon-download {
          cursor: pointer;
        }
      }
      .singList_title_biaoti {
        width: 30%;
        height: 100%;
        //background: green;
        cursor: pointer;
      }
      .singList_title_geshou {
        width: 15%;
        height: 100%;
        //background: pink;
      }
      .singList_title_zhuanji {
        width: 20%;
        height: 100%;
        margin-right: 10px;
        //background: yellow;
      }
      .singList_title_shijian {
        width: 10%;
        height: 100%;
        //background: orange;
      }
    }
  }
  .geShouList {
    padding-top: 30px;
    padding-bottom: 30px;
    width: 96%;
    margin: auto;
    cursor: pointer;
    .geShouList_inside {
      display: flex;
      align-items: center;
      margin-bottom: 15px;
      .el-image {
        width: 60px;
        height: 60px;
        border-radius: 5px;
        margin-right: 10px;
      }
      .geShouList_inside_name {
        margin-right: 10px;
      }
    }
  }
  .shiping_container_contact {
    padding-top: 30px;
    padding-bottom: 30px;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    .shiping_container_contact_inside {
      width: 30%;
      height: 200px;
      margin-right: 25px;
      //background: cyan;
      margin-bottom: 20px;
      .shiping_container_contact_inside_img {
        width: 100%;
        height: 70%;
        //background: red;
        margin-bottom: 10px;
        cursor: pointer;
        .el-image {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
        .shiping_container_contact_inside_durationms {
          position: relative;
          bottom: 22px;
          left: 175px;
          color: white;
          width: 50px;
          @include flex;
        }
      }
      .shiping_container_contact_inside_title {
        @include white_space;
        margin-bottom: 5px;
        font-size: 15px;
      }
      .shiping_container_contact_inside_arc {
        color: #aca8a8;
        font-size: 14px;
      }
    }
  }
  .sousuo_gedan {
    padding-top: 30px;
    padding-bottom: 30px;
    width: 96%;
    margin: auto;
    cursor: pointer;
    .sousuo_gedan_inside {
      display: flex;
      margin-bottom: 15px;
      .sousuo_gedan_inside_left {
        width: 50%;
        display: flex;
        align-items: center;
        .el-image {
          width: 60px;
          height: 60px;
          border-radius: 5px;
          margin-right: 10px;
        }
        .sousuo_gedan_inside_left_name {
          font-size: 14px;
        }
      }
      .sousuo_gedan_inside_middle {
        width: 20%;
        color: #909399;
        @include flex;
        font-size: 14px;
      }
      .sousuo_gedan_inside_right {
        width: 30%;
        @include flex;
        .sousuo_gedan_inside_right_by {
          font-size: 12px;
          color: #909399;
          margin-right: 5px;
        }
        .sousuo_gedan_inside_right_name {
          font-size: 14px;
        }
      }
    }
  }
  .yonghu_contact {
    padding-top: 30px;
    padding-bottom: 30px;
    width: 96%;
    margin: auto;
    cursor: pointer;
    .yonghu_contact_inside {
      display: flex;
      margin-bottom: 15px;
      .yonghu_contact_inside_left {
        width: 10%;
        .el-image {
          width: 60px;
          height: 60px;
          border-radius: 50%;
          margin-right: 10px;
        }
      }
      .yonghu_contact_inside_middle {
        width: 70%;
        display: flex;
        align-items: center;
        span {
          font-size: 14px;
        }
      }
      .yonghu_contact_inside_right {
        width: 20%;
        font-size: 12px;
        color: #909399;
        @include white_space;
        display: flex;
        align-items: center;
      }
    }
  }
  .el-dialog__body {
    padding: 0px 20px 20px 20px;
    .dialog {
      margin-bottom: 15px;
      cursor: pointer;
    }
    .noSing {
      @include flex;
      height: 40px;
    }
    .buttons {
      @include flex;
      .buttons_inside {
        width: 60%;
        display: flex;
        .quereng {
          background: $wangYiYunColor;
          color: white;
        }
        .quereng:hover {
          background: #c20117;
          color: white;
        }
        .quxiao:hover {
          background: rgba(240, 233, 233, 0.932);
          color: #606266;
        }
      }
    }
  }
  .pagination {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
  }
}
</style>
